#import "sprite_game_enemy_5.h"

@implementation SpriteGameEnemy5

- (id)initSpriteGameEnemy5
{
	if ((self = [super initSpriteGameEnemy]))
	{
		objectName_ = "object sprite game enemy type 5";
		
		/*box2d
		*/
		fixtureBody_ = NULL;
		fixtureArmor_ = NULL;
	}
	return self;
}

- (void)createBody
{
	int i;
	int _VertexCount;
	float _Ratio;
	b2Vec2 *_Vertex;
	b2PolygonShape _PolygonShape;
	b2FixtureDef _FixtureDef;

	[super createBody];

	_Ratio = 1 / CMgrGamePhysics::Ratio();
	_FixtureDef.density = 1.0f;
	_FixtureDef.isSensor = true;
	
	/*body
	*/
	_VertexCount = g_CfgGameEnemyDataTable[type_].box2d_collision_point_table_body.size();
	_Vertex = ptCreateCollisionVertex(&g_CfgGameEnemyDataTable[type_].box2d_collision_point_table_body);
	for (i = 0; i < _VertexCount; ++i)
	{
		_Vertex[i] = ptScaleVector_same(_Vertex[i], _Ratio);
	}
	_PolygonShape.Set(_Vertex, _VertexCount);
	free(_Vertex);
	_FixtureDef.shape = &_PolygonShape;
	fixtureBody_ = box2dBody_->CreateFixture(&_FixtureDef);
	/*armor
	*/
	_VertexCount = g_CfgGameEnemyDataTable[type_].box2d_collision_point_table_armor.size();
	_Vertex = ptCreateCollisionVertex(&g_CfgGameEnemyDataTable[type_].box2d_collision_point_table_armor);
	for (i = 0; i < _VertexCount; ++i)
	{
		_Vertex[i] = ptScaleVector_same(_Vertex[i], _Ratio);
	}
	_PolygonShape.Set(_Vertex, _VertexCount);
	free(_Vertex);
	_FixtureDef.shape = &_PolygonShape;
	fixtureArmor_ = box2dBody_->CreateFixture(&_FixtureDef);
}

- (void)destroyBody
{
	[super destroyBody]
	fixtureBody_ = NULL;
	fixtureArmor_ = NULL;
}

- (void)PlayEffectCover
{
	CCSequence *_Seq;

	if (nil != effectCover_)
	{
		[effectCover_ stopAllActions];
		_Seq = [CCSequence actions:[CCShow action], [CCAnimate actionWithAnimation:uiCreateAnimationObject(&g_CfgGameEnemyDataTable[type_].ani_cover)], [CCHide action], nil];
		[effectCover_ runAction:_Seq];
	}
}

- (void)ActionBoss3Slave
{
	CCSequence *_Seq;
	id _ActionMove;
	CCCallFuncN *_CallBackMoveOver;

	if (state_ == ENEMY_STATE_DIE)
	{
		return;
	}

	[self PlayAni:ENEMY_ANI_MOVE];
	if (uiPointInCenterRect(self.positionInPixels, g_CfgGameScrrenArea[9]))
	{
		_ActionMove = tcCreateActionMove(self.positionInPixels, g_CfgGameScrrenArea[0].center, moveSpeed_);
	}
	else if (uiPointInCenterRect(self.positionInPixels, g_CfgGameScrrenArea[19]))
	{
		_ActionMove = tcCreateActionMove(self.positionInPixels, g_CfgGameScrrenArea[2].center, moveSpeed_);
	}
	else
	{
		assert(false);
	}
	_CallBackMoveOver = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackBoss3SlaveActionMoveOver:)];
	_Seq = [CCSequence actions:_ActionMove, _CallBackMoveOver, nil];
	[self runAction:_Seq];
}

- (void)ActionBoss3SlaveDisappear
{
	CCSequence *_Seq;
	id _ActionMove;
	CCCallFuncN *_CallBack;

	if (state_ == ENEMY_STATE_DIE)
	{
		return;
	}

	[self StopAction];
	[self PlayAni:ENEMY_ANI_MOVE];
	if (self == boss3Handle_.boss3SlaveLeftHandle)
	{
		_ActionMove = tcCreateActionMove(self.positionInPixels, g_CfgGameScrrenArea[9].center, moveSpeed_);
	}
	else if (self == boss3Handle_.boss3SlaveRightHandle)
	{
		_ActionMove = tcCreateActionMove(self.positionInPixels, g_CfgGameScrrenArea[19].center, moveSpeed_);
	}
	_CallBack = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackBoss3SlaveActionDisappearMoveOver:)];
	_Seq = [CCSequence actions:_ActionMove, _CallBack, nil];
	[self runAction:_Seq];
}

- (void)CallBackBoss3SlaveActionMoveOver:(id)Sender
{
	[self ActionAttack];
}

- (void)CallBackBoss3SlaveActionDisappearMoveOver:(id)Sender
{
	[g_LayerGameObject RemoveEnemy:self];
}

@end